package com.netease.cloud.cm.task;

import com.netease.cloud.cm.common.Constants;
import com.netease.cloud.cm.common.DailySummary;
import com.netease.cloud.cm.util.AlarmAlertUtils;
import com.netease.cloud.cm.util.GetEnvConfig;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * 每天执行一次的定时任务：将一天测试的情况汇总后发送一封报表
 */
@Slf4j
public class DailyJob implements Job {

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		log.info("---------------- Start Job ----------------");
		DailySummary daily = null;
		if (context != null) {
			daily = (DailySummary) context.getJobDetail().getJobDataMap().get(Constants.SUMMARY_KEY);
		} else {
			daily = new DailySummary(GetEnvConfig.getEnv());
		}

		AlarmAlertUtils.sendAlarm(daily.toString(), false);
		daily.reset();
		log.info("---------------- End Job ----------------");
	}
}
